p=5
rcnt=1
wcnt=1

function runRead() {
    mkdir -p data rd
    rm -rf data/* rd/*

    make clean
    make build

    for i in $(seq -w ${wcnt}); do
        dd if=/dev/urandom of=data/${i} bs=1M count=$1
    done

    wStart=$( date +%s%3N )

    for i in $(seq -w ${wcnt}); do
        ./evenodd write ${p} data/${i} ${i}
    done

    wEnd=$( date +%s%3N )
    rm -rf disk_2 disk_1
    rStart=$( date +%s%3N )

    for i in $(seq -w ${rcnt}); do
        ./evenodd read ${p} ${i} rd/${i}
    done

    rEnd=$( date +%s%3N )

    echo "write time used: $((wEnd-wStart)) ms"
    echo "read time used: $((rEnd-rStart)) ms"

    diff -sr data rd
    if [ $? -eq 0 ]; then
        echo "all test passed"
        make clean
        rm -r data rd
    else
        echo "test failed"
    fi
}

runRead $((8*1024))
